//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package common;

import ove.crypto.digest.Blake2b.Digest;

import java.security.SecureRandom;

public class HaydayNonce {
    private byte[] hdnonce;

    public HaydayNonce(byte[] nonce, byte[] clientKey, byte[] serverKey) {
        if(clientKey == null) {
            if(nonce != null) {
                this.hdnonce = new byte[nonce.length];
                System.arraycopy(nonce, 0, this.hdnonce, 0, nonce.length);
            } else {
                this.hdnonce = new byte[24];
                (new SecureRandom()).nextBytes(this.hdnonce);
            }
        } else {
            Digest b = Digest.newInstance(24);
            if(nonce != null) {
                b.update(nonce);
            }

            b.update(clientKey);
            b.update(serverKey);
            this.hdnonce = b.digest();
        }

    }

    public byte[] get() {
        return this.hdnonce;
    }

    public void increment() {
        int incval = 2;

        for(int i = 0; i < this.hdnonce.length; ++i) {
            int v = incval + (this.hdnonce[i] & 255);
            this.hdnonce[i] = (byte)v;
            incval = v >> 8;
        }

    }
}
